<div class="layui-upload">
    <button type="button" class="layui-btn" id="one_upload{{$id}}">上传附件</button>
    <div class="layui-upload-list">
        <img class="layui-upload-img" id="one_upload_img{{$id}}" width="100px" @if(!empty($file)) src="{{$file['uri']}}" @endif >
        <p id="demoText"></p>
        <input type="hidden" id="file_one{{$id}}" name="file_one{{$id}}"  @if(!empty($file)) value="{{$file['id']}}" @endif>
    </div>
</div>
<script>
    $(function(){
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#one_upload{{$id}}'
            ,url: '{{URL::action('Api\UploadController@upload')}}'
            ,accept: 'file' //普通文件
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#one_upload_img{{$id}}').attr('src', result); //图片链接（base64）
                    //$("#file_one").val(result);
                    layer.msg('上传中，请稍候' ,{anim: 1,time: 3000000});
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code != 200){
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#file_one{{$id}}").val(res.data.id);
                return layer.msg('上传成功');
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

    });
    })
</script>